package sm.dbdict.def;

import java.util.ArrayList;
import java.util.List;

public class Key implements Cloneable {
	private Integer flags;

	private List<String> name;

	private List<SqlIndex> sqlIndexes;

	public List<SqlIndex> getSqlIndexes() {
		return sqlIndexes;
	}

	public void setSqlIndexes(List<SqlIndex> sqlIndexes) {
		this.sqlIndexes = sqlIndexes;
	}

	public Integer getFlags() {
		return flags;
	}

	public void setFlags(Integer flags) {
		this.flags = flags;
	}

	public List<String> getName() {
		return name;
	}

	public void setName(List<String> name) {
		this.name = name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((flags == null) ? 0 : flags.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((sqlIndexes == null) ? 0 : sqlIndexes.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Key other = (Key) obj;
		if (flags == null) {
			if (other.flags != null)
				return false;
		} else if (!flags.equals(other.flags))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (sqlIndexes == null) {
			if (other.sqlIndexes != null)
				return false;
		} else if (!sqlIndexes.equals(other.sqlIndexes))
			return false;
		return true;
	}

	@Override
	public Object clone() {
		try {
			Key clonedObj = (Key) super.clone();
			clonedObj.flags = flags;
			if (name != null) {
				clonedObj.name = new ArrayList<String>();
				for (String n : name) {
					clonedObj.name.add(n);
				}
			}
			if (sqlIndexes != null) {
				clonedObj.sqlIndexes = new ArrayList<SqlIndex>();
				for (SqlIndex index : sqlIndexes) {
					clonedObj.sqlIndexes.add((SqlIndex) index.clone());
				}
			}
			return clonedObj;
		} catch (CloneNotSupportedException e) {
			// this shouldn't happen, since we are Cloneable
			throw new InternalError();
		}
	}

}
